package com.jumi.microservice.stock.service.impl;

import com.jumi.microservice.material.dto.JmUnitResponse;
import com.jumi.microservice.material.dto.category.JmCategoryResponse;
import com.jumi.microservice.material.dto.supplier.JmSupplierResponse;
import com.jumi.microservice.material.service.JmCategoryService;
import com.jumi.microservice.material.service.JmMaterialSmallUnitService;
import com.jumi.microservice.material.service.JmSupplierService;
import com.jumi.microservice.material.service.JmWarehouseService;
import com.jumi.microservice.stock.service.CommonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description
 * @ClassName CommonServiceImpl
 * @Author Abel Yang
 * @Date 2020/9/11/011 17:17
 **/
@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    private JmCategoryService jmCategoryService;

    @Resource
    private JmMaterialSmallUnitService jmMaterialSmallUnitService;

    @Resource
    private JmSupplierService jmSupplierService;

    @Resource
    private JmWarehouseService jmWarehouseService;

    @Override
    public Map<Long, JmSupplierResponse> getSupplierMapByIds(List<Long> supplierIds) {
        Map<Long, JmSupplierResponse> result = new HashMap<>();
        if (supplierIds.size() == 0) {
            return result;
        }
        return jmSupplierService.findBySupplierIds(supplierIds).stream().collect(Collectors.toMap(JmSupplierResponse::getSupplierId, k -> k));
    }

    @Override
    public Map<Long, JmCategoryResponse> getCategoryMapByIds(List<Long> categoryIds) {
        Map<Long, JmCategoryResponse> result = new HashMap<>();
        if (categoryIds.size() == 0) {
            return result;
        }
        return jmCategoryService.findByCategoryIds(categoryIds).stream().collect(Collectors.toMap(JmCategoryResponse::getCategoryId, k -> k));
    }

    @Override
    public Map<Integer, JmUnitResponse> getUnitMapByIds(List<Integer> unitIds) {
        Map<Integer, JmUnitResponse> result = new HashMap<>();
        if (unitIds.size() == 0) {
            return result;
        }
        return jmMaterialSmallUnitService.findByUnitIds(unitIds).stream().collect(Collectors.toMap(JmUnitResponse::getSmunitId, k -> k));
    }

}
